package com.vben.system.api.feign.fallback;

import com.vben.common.core.util.R;
import com.vben.system.api.entity.SysUserLoginLog;
import com.vben.system.api.feign.RemoteUserLoginLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RemoteUserLoginLogFallbackFactory implements FallbackFactory<RemoteUserLoginLogService> {

    @Override
    public RemoteUserLoginLogService create(Throwable throwable) {
        log.error("用户登陆日志服务调用失败:{}", throwable.getMessage());
        return new RemoteUserLoginLogService() {
            @Override
            public R<SysUserLoginLog> getByLoginId(String loginId) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<Boolean> addLoginLog(SysUserLoginLog sysUserLoginLog) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<Boolean> updateLoginLog(SysUserLoginLog sysUserLoginLog) {
                return R.failed(throwable.getMessage());
            }
        };
    }
}
